<template>
	<div class="card">
		<div class="phone-content">
			<div class="avatar">
				<img :src="message._from.portrait" alt="" />
			</div>
			<div class="phone-content-title">
				我想要你的简历，你是否同意？
			</div>
		</div>
		<div class="buttons">
			<div class="button" @click="refuse">拒绝</div>
			<div class="button" @click="agree">同意</div>
		</div>
	</div>
</template>

<script>
	import wfc from "@/wfc/client/wfc";
	import store from "@/store";
	import Draft from "../../../util/draft";
	import QuoteInfo from "@/wfc/model/quoteInfo";
	import covertContactMessage from "@/wfc/messages/covertContactMessage";
	import {
		getJobContact,
		getInteractionDic,
		setImInteraction,
		getResume
	} from "@/common/im";

	export default {
		name: "NormalInMessageContentView",
		props: {
			message: null,
			jobId:null,
			dfid:null,
			jobContactData:null
		},
		data() {
			return {
				sharedConversationState: store.state.conversation,
				isClick: true,
				// jobContactData: {},
			};
		},
		mounted() {
			// getJobContact().then((res) => {
			// 	console.log("获取jobContactData2", res);
			// 	this.jobContactData = res.result;
			// 	const resume = this.getJobContactData('resume');
			// 	console.log('resume, jobContactData', this.jobContactData)
			// 	if (resume == -1 || resume == 2) {
			// 		this.isClick = false;
			// 	}
			// });
		},
		methods: {
			getJobContactData(type, isReversed = false) {
				console.log("this.jobContactData: >>", this.jobContactData);
				const field = getInteractionDic(type, isReversed);
				return this.jobContactData[field];
			},
			// 拒绝
			refuse() {
				if (!this.isClick) {
					return;
				}
				this.isClick = false;
				const field = getInteractionDic(this.message.messageContent.extra);
				setImInteraction(field, -1,this.jobId,this.dfid);
				this.send("-1");
			},
			// 同意
			async agree() {
				if (!this.isClick) {
					return;
				}
				this.isClick = false;
				console.log('同意了');
				const field = getInteractionDic(this.message.messageContent.extra);
				setImInteraction(field, 2,this.jobId,this.dfid);
				const type = this.message.messageContent.extra;

				const resume = await getResume();
				this.send(JSON.stringify(resume.result));
			},
			send(text) {
				const phoneMessageContent = new covertContactMessage("resume", text);
				const type = this.message.messageContent.extra;
				let quotedMessage = this.sharedConversationState.quotedMessage;
				if (quotedMessage) {
					let quoteInfo = QuoteInfo.initWithMessage(quotedMessage);
					phoneMessageContent.setQuoteInfo(quoteInfo);
					store.quoteMessage(null);
				}

				let currentConversation =
					this.sharedConversationState.currentConversationInfo.conversation;

				wfc.sendConversationMessage(currentConversation, phoneMessageContent);
				this.text = "";
				this.mentions = [];
				Draft.setConversationDraft(currentConversation, "", null);
				store.loadConversationHistoryMessages(()=>{},()=>{});
			},

		},
	};
</script>

<style scoped>
</style>